<template>
  <div class="appDemo">
    <md-button type="primary" @click="getToken">getToken</md-button>
    <md-button type="primary" @click="jumpValue">跳原生登陆页面</md-button>
    <md-button type="primary" @click="jumpValue2">跳通用二级页面</md-button>
    <md-button type="primary" @click="naviInit">naviInit</md-button>
    <md-button type="primary" @click="verifyIdentity">verifyIdentity</md-button>
    <md-button type="primary" @click="outBrowser">outBrowser</md-button>
    <md-button type="primary" @click="back">back</md-button>
    <md-button type="primary" @click="popView">popView</md-button>
    <md-button type="primary" @click="getSystemInfo">getSystemInfo</md-button>
    <div style="font-size:14px;">
      {{systemInfo}}
    </div>
    <div style="font-size:14px;">
      {{tokenInfo}}
    </div>
    <div style="font-size:14px;">
      {{verifyIdentityInfo}}
    </div>
  </div>
</template>

<script>
  import {
    Button,
    Toast
  } from 'mand-mobile'

  export default {
    data() {
      return {
        buttonCallBack: [],
        systemInfo: {},
        tokenInfo: {},
        verifyIdentityInfo: {}
      }
    },
    components: {
      'md-button': Button
    },
    created() {
      Toast.info(navigator.userAgent.toLowerCase())
    },
    methods: {
      getToken() {
        let _this = this
        Toast.info('开始调用getToken')
        this.$app.getToken().then(function (res) {
          console.log('调用成功')
          Toast.info(res)
          _this.tokenInfo = res
        }, function () {
          console.log('调用失败')

        })
      },
      jumpValue() {
        Toast.info('开始调用jumpValue：code' + this.$app.PAGE_CODE_ENUM.CUSTOMER_LOGIN)
        this.$app.jumpValue({
          pageCode: this.$app.PAGE_CODE_ENUM.CUSTOMER_LOGIN,
        })
      },
      jumpValue2() {
        Toast.info('开始调用jumpValue：code' + this.$app.PAGE_CODE_ENUM.COMMON_PRIMARY_PAGE)
        this.$app.jumpValue({
          pageCode: this.$app.PAGE_CODE_ENUM.COMMON_PRIMARY_PAGE,
          url: window.location.href.replace(window.location.hash, '') + '#' + '/about'
        })
      },
      naviInit() {
        let _this = this
        let params = {
          setTitle: {
            title: '瑞仟基金'
          },
          setButton: {
            buttonArrary: [{
                jsFunction: this.share,
                text: '分享'
              },
              {
                jsFunction: this.butFunc2,
                text: '自定义按钮二'
              }, {
                jsFunction: this.butFunc3,
                text: '自定义按钮二'
              }
            ]
          }
        }
        Toast.info('开始调用naviInit')
        this.$app.naviInit(params).then(function (res) {
          _this.buttonCallBack = window.$appBridge.naviInit.buttonCallBack
          Toast.info(res)
        }, function () {
          console.log('调用失败')

        })
      },
      butFunc1() {
        Toast.info('按钮1')
        console.log('按钮1')
      },
      butFunc2() {
        Toast.info('按钮2')
        console.log('按钮2')
      },
      butFunc3() {
        Toast.info('按钮3')
        console.log('按钮3')
      },
      share() {
        Toast.info('开始调用share')
        let params = {
          shareChannel: [{
            type: this.$app.SHARE_TYPE_ENUM.WX_FRIEND,
            shareType: 1,
            text: 'app分享测试'
          }, {
            type: this.$app.SHARE_TYPE_ENUM.WX_SPACE,
            shareType: 2,
            text: 'app分享测试',
            image: this.verifyIdentityInfo.nativeData.imgList[0]
          }]
        }
        this.$app.share(params)
      },
      verifyIdentity() {
        let _this = this
        Toast.info('开始调用verifyIdentity')
        let params = {
          count: 1,
          sizeType: 100,
          sourceType: [
            '相机', '相册'
          ]
        }
        _this.$app.verifyIdentity(params).then((res) => {
          _this.verifyIdentityInfo = res
        })
      },
      outBrowser() {
        Toast.info('开始调用outBrowser')
        let params = {
          url: 'https://www.baidu.com/'
        }
        this.$app.outBrowser(params).then(res => {
          Toast.info(res)
        })
      },
      back() {
        Toast.info('开始调用back')
        this.$app.back().then(res => {
          Toast.info(res)
        })
      },
      popView() {
        Toast.info('开始调用popView')
        this.$app.popView().then(res => {
          Toast.info(res)
        })
      },
      getSystemInfo() {
        let _this = this
        Toast.info('开始调用systemInfo')
        this.$app.systemInfo().then(res => {
          _this.systemInfo = res
        })
      },

    }
  }
</script>

<style lang="less" scoped>
  .md-button {
    margin: 0.1rem auto;
    width: 92%;
  }
</style>